package jdbc;

import java.io.Reader;
import java.sql.*;

/**
 * 测试使用JDBCUtil工具类
 */
public class Demo11 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;

        try {
            //连接数据库
            conn=JDBCUtil.getMysqlConn();
            System.out.println(conn);
            ps=conn.prepareStatement("select * from t_user where id>?");
            ps.setInt(1,20015);
            rs=ps.executeQuery();
            Reader r=null;
            StringBuilder sb=null;
            while (rs.next()){
                Clob c=rs.getClob(5);
                r=c.getCharacterStream();
                int temp=0;
                sb=new StringBuilder();
                while ((temp=r.read())!=-1) {
                    sb.append((char)temp);
                }
                System.out.println(rs.getInt(1)+"--"+rs.getString(2)+"--"+rs.getTimestamp(4)+"--"+sb.toString()+"--"+rs.getBlob(6));
            }
            r.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //只关闭连接
            JDBCUtil.close(rs,ps,conn);
        }
    }
}
